﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using COM.OA.Entity;
using COM.OA.BLL;
using System.Collections.Generic;

public partial class qs_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //取查询页面的姓名
        string uname = this.Request.QueryString["u_username"];
        string where = "u_username='{0}'";
        //根据姓名查部门ＩＤ
        where = string.Format(where, uname);
        IList<users> list =  usersBLL.Select(where);
        users u = list[0];
        int bumenId = u.u_dept_id;
        //根据部门ＩＤ查部门名
        string where1 = "dept_id='{0}'";
        where1 = string.Format(where1, bumenId);
        IList<department> lists = departmentBLL.Select(where1);
        department dt = lists[0];
        string bumen = dt.dept_department;

        int uid = u.u_id;

        string where2 = "al_u_id='{0}'";
        where2 = string.Format(where2, uid);
        IList<addresslist> listad = addresslistBLL.Select(where2);
        addresslist dl = listad[0];
      
        
        this.txtUname.Text = uname;
        this.txtBumen.Text = bumen;
        this.txtZhiWu.Text = dl.al_duty;
        this.txtShouji.Text = dl.al_mobile;
        this.txtXiaolingtong.Text = dl.al_smallclever;
        this.txtBangong.Text = dl.al_worktelephone;
        this.txtFenji.Text = dl.al_extension;
        this.txtChuanZhen.Text = dl.al_fax;
        this.txtEmail.Text = dl.al_email;
        this.txtBeiZhu.Text = dl.al_remark;
        this.txtAdd.Text = dl.al_address;
        this.txtMsn.Text = dl.al_msn;
        this.txtQQ.Text = dl.al_qq;
        
        
    }
    protected void btChongZhi_Click(object sender, EventArgs e)
    {
        
        this.txtZhiWu.Text = "";
        this.txtShouji.Text = "";
        this.txtXiaolingtong.Text = "";
        this.txtBangong.Text = "";
        this.txtFenji.Text = "";
        this.txtEmail.Text = "";
        this.txtQQ.Text = "";
        this.txtChuanZhen.Text = "";
        this.txtMsn.Text = "";
        this.txtAdd.Text = "";
        this.txtBeiZhu.Text = "";
    }
    protected void btXiuGai_Click(object sender, EventArgs e)
    {
        //取文本数值
        string uname=this.txtUname.Text;
        string bumen=this.txtBumen.Text ;
        string zhiwu = this.txtZhiWu.Text;
        string shouji = this.txtShouji.Text;
        string xiaolingtong = this.txtXiaolingtong.Text;
        string bangong = this.txtBangong.Text;
        string fenji = this.txtFenji.Text;
        string email = this.txtEmail.Text;
        string qq = this.txtQQ.Text;
        string chuanzhen = this.txtChuanZhen.Text;
        string msn = this.txtMsn.Text;
        string add = this.txtAdd.Text;
        //取备注
        string beizhu = this.txtBeiZhu.Text;

        string where = "u_username='{0}'";
        //根据姓名查ＩＤ
        where = string.Format(where, uname);
        IList<users> list = usersBLL.Select(where);
        users u = list[0];
        int uid = u.u_id;

        //取部门ID
        string where1 = "dept_department='{0}'";
        where1 = string.Format(where1, bumen);
        IList<department> listbumen = departmentBLL.Select(where1);
        department dt = listbumen[0];
        int bumenId = dt.dept_id;

        //根据姓名ＩＤ查出这条数据
        
        string where2 = "al_u_id='{0}'";
        where2 = string.Format(where2, uid);
        IList<addresslist> listtongxunlu = addresslistBLL.Select(where2);
        
       
        //接受查询信息重新副职
         addresslist al = listtongxunlu[0];

        al.al_u_id=uid;
        al.al_dept_id = bumenId;
        al.al_duty = zhiwu;
        al.al_mobile = shouji;
        al.al_smallclever = xiaolingtong;
        al.al_worktelephone = bangong;
        al.al_extension = fenji;
        al.al_fax = chuanzhen;
        al.al_email = email;
        al.al_qq = qq;
        al.al_msn = msn;
        al.al_address = add;

        
        //修改通讯录表
        addresslistBLL.Update(al);
        //if ()
        //{ //跳到查询页
            this.Response.Redirect("danweitxl.aspx");
        //}
        //else { this.Response.Write(string.Format(GetRedirect.WINALERT, "修改失败")); }
        
        
    }
   
}
